package com.wcl.nullmusic.mode.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.wcl.nullmusic.mode.Anthology_Album;
import com.wcl.nullmusic.mode.Anthology_Track;
import com.wcl.nullmusic.mode.Anthology_Track_List;
import com.wcl.nullmusic.mode.Recommend_CategoryContents_List;
import com.wcl.nullmusic.mode.Recommend_CategoryContents_List_List;
import com.wcl.nullmusic.mode.Recommend_FocusImages_List;
import com.wcl.nullmusic.mode.SongDetail_Info;
import com.wcl.nullmusic.utils.Contant;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/18.
 */
public class NullMusic_DBTools {
    private NullMusicDBHelper helper;
    private SQLiteDatabase db;
    private Context context;

    public NullMusic_DBTools(Context context) {
        this.context = context;
        helper = new NullMusicDBHelper(context, Contant.NULLMUSIC_DBNAME, null, Contant.VERSON);
        db = helper.getWritableDatabase();
    }

    /**
     * Recommend_Recyclerview_list的数据存储
     *
     * @param datas
     */
    public void saveDatas_Recommend_Recyclerview_List(List<Recommend_CategoryContents_List> datas) {
        ContentValues values = new ContentValues();
        for (int i = 0; i < datas.size(); i++) {
            values.put("title", datas.get(i).getTitle());
            values.put("moduleType", datas.get(i).getModuleType());
            values.put("position", i + "");
            if (datas.get(i).isHasMore())
                values.put("hasMore", 1);
            else
                values.put("hasMore", -1);
            long id = db.insert(Contant.RECOMMEND_RECYCLERVIEW_LIST_TABLENAME, null, values);
            values.clear();

            saveDatas_Recommend_Recyclerview_List_List(datas.get(i).getList(), i + "");
        }
    }

    /**
     * Recommend_Recyclerview_list的数据查询
     *
     * @return
     */
    public List<Recommend_CategoryContents_List> queryAll_Recommend_Recyclerview_List() {
        Cursor cursor = db.query(Contant.RECOMMEND_RECYCLERVIEW_LIST_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            boolean hasMore = false;
            List<Recommend_CategoryContents_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String position = cursor.getString(cursor.getColumnIndex("position"));
                String title = cursor.getString(cursor.getColumnIndex("title"));
                int moduleType = cursor.getInt(cursor.getColumnIndex("moduleType"));
                int flag = cursor.getInt(cursor.getColumnIndex("hasMore"));
                if (flag == 1)
                    hasMore = true;
                else if (flag == -1)
                    hasMore = false;

                Recommend_CategoryContents_List list = new Recommend_CategoryContents_List();
                list.setPosition(position);
                list.setTitle(title);
                list.setModuleType(moduleType);
                list.setHasMore(hasMore);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Recommend_Recyclerview_list的数据删除
     */
    public void deleteAll_Recommend_Recyclerview_List() {
        db.delete(Contant.RECOMMEND_RECYCLERVIEW_LIST_TABLENAME, null, null);
    }

    /**
     * Recommend_Recyclerview_list的数据更新
     *
     * @param datas
     */
    public void updateAll_Recommend_Recyclerview_List(List<Recommend_CategoryContents_List> datas) {
        deleteAll_Recommend_Recyclerview_List();
        saveDatas_Recommend_Recyclerview_List(datas);
    }

    /**
     * Recommend_Recyclerview_list_list的数据存储
     */
    public void saveDatas_Recommend_Recyclerview_List_List(List<Recommend_CategoryContents_List_List> datas, String position) {
        ContentValues values = new ContentValues();
        for (Recommend_CategoryContents_List_List data : datas) {
            values.put("position", position);
            values.put("title", data.getTitle());
            values.put("subtitle", data.getSubtitle());
            values.put("key", data.getKey());
            values.put("nickname", data.getNickname());
            values.put("coverPath", data.getCoverPath());
            values.put("intro", data.getIntro());
            values.put("coverSmall", data.getCoverSmall());
            values.put("coverMiddle", data.getCoverMiddle());
            values.put("tracksCounts", data.getTracksCounts());
            values.put("albumId", data.getAlbumId());
            db.insert(Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Recommend_Recyclerview_list_list插入一条数据
     */
    public void insert_Recommend_Recyclerview_List_List(Recommend_CategoryContents_List_List data) {
        ContentValues values = new ContentValues();
        values.put("title", data.getTitle());
        values.put("subtitle", data.getSubtitle());
        values.put("key", data.getKey());
        values.put("nickname", data.getNickname());
        values.put("coverPath", data.getCoverPath());
        values.put("intro", data.getIntro());
        values.put("coverSmall", data.getCoverSmall());
        values.put("coverMiddle", data.getCoverMiddle());
        values.put("tracksCounts", data.getTracksCounts());
        values.put("albumId", data.getAlbumId());
        db.insert(Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME, null, values);
        values.clear();
    }

    /**
     * Recommend_Recyclerview_list_list查询position字段
     *
     * @return
     */
    public List<Recommend_CategoryContents_List_List> queryPostion_Recommend_Recyclerview_List_List(String position) {
        String sql = "select * from " + Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME + " where position = ? ";
        Cursor cursor = db.rawQuery(sql, new String[]{position});
        if (cursor != null) {
            List<Recommend_CategoryContents_List_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String list_id = cursor.getString(cursor.getColumnIndex("position"));
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String subtitle = cursor.getString(cursor.getColumnIndex("subtitle"));
                String key = cursor.getString(cursor.getColumnIndex("key"));
                String nickname = cursor.getString(cursor.getColumnIndex("nickname"));
                String coverPath = cursor.getString(cursor.getColumnIndex("coverPath"));
                String intro = cursor.getString(cursor.getColumnIndex("intro"));
                String coverSmall = cursor.getString(cursor.getColumnIndex("coverSmall"));
                String coverMiddle = cursor.getString(cursor.getColumnIndex("coverMiddle"));
                int tracksCounts = cursor.getInt(cursor.getColumnIndex("tracksCounts"));
                int albumId = cursor.getInt(cursor.getColumnIndex("albumId"));

                Recommend_CategoryContents_List_List list = new Recommend_CategoryContents_List_List();
                list.setPosition(list_id);
                list.setTitle(title);
                list.setSubtitle(subtitle);
                list.setKey(key);
                list.setNickname(nickname);
                list.setCoverPath(coverPath);
                list.setIntro(intro);
                list.setCoverSmall(coverSmall);
                list.setCoverMiddle(coverMiddle);
                list.setTracksCounts(tracksCounts);
                list.setAlbumId(albumId);
                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Recommend_Recyclerview_list_list的数据查询
     *
     * @return
     */
    public List<Recommend_CategoryContents_List_List> queryAll_Recommend_Recyclerview_List_List() {
        Cursor cursor = db.query(Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Recommend_CategoryContents_List_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String subtitle = cursor.getString(cursor.getColumnIndex("subtitle"));
                String key = cursor.getString(cursor.getColumnIndex("key"));
                String nickname = cursor.getString(cursor.getColumnIndex("nickname"));
                String coverPath = cursor.getString(cursor.getColumnIndex("coverPath"));
                String intro = cursor.getString(cursor.getColumnIndex("intro"));
                String coverSmall = cursor.getString(cursor.getColumnIndex("coverSmall"));
                String coverMiddle = cursor.getString(cursor.getColumnIndex("coverMiddle"));
                int tracksCounts = cursor.getInt(cursor.getColumnIndex("tracksCounts"));
                int albumId = cursor.getInt(cursor.getColumnIndex("albumId"));

                Recommend_CategoryContents_List_List list = new Recommend_CategoryContents_List_List();
                list.setTitle(title);
                list.setSubtitle(subtitle);
                list.setKey(key);
                list.setNickname(nickname);
                list.setCoverPath(coverPath);
                list.setIntro(intro);
                list.setCoverSmall(coverSmall);
                list.setCoverMiddle(coverMiddle);
                list.setTracksCounts(tracksCounts);
                list.setAlbumId(albumId);
                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Recommend_Recyclerview_list_list的数据删除
     */
    public void deleteAll_Recommend_Recyclerview_List_List() {
        db.delete(Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME, null, null);
    }

//    /**
//     * Recommend_Recyclerview_list_list的数据更新
//     *
//     * @param datas
//     */
//    public void updateAll_Recommend_Recyclerview_List_List(List<Recommend_CategoryContents_List_List> datas) {
//        deleteAll_Recommend_Recyclerview_List_List();
//        saveDatas_Recommend_Recyclerview_List_List(datas, 0);
//    }


//        ===================================Viewpager====================================

    /**
     * Recommend_Viewpager的数据存储
     *
     * @param datas
     */
    public void saveDatas_Recommend_Viewpager(List<Recommend_FocusImages_List> datas) {
        ContentValues values = new ContentValues();
        for (Recommend_FocusImages_List data : datas) {


            values.put("shortTitle", data.getShortTitle());
            values.put("longTitle", data.getLongTitle());
            values.put("pic", data.getPic());
            values.put("trackId", data.getTrackId());
            values.put("type", data.getType());
            values.put("albumId", data.getAlbumId());
            values.put("specialId", data.getSpecialId());


            long id = db.insert(Contant.RECOMMEND_VIEWPAGER_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Recommend_Viewpager的数据查询
     *
     * @return
     */
    public List<Recommend_FocusImages_List> queryAll_Recommend_Viewpager() {
        Cursor cursor = db.query(Contant.RECOMMEND_VIEWPAGER_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            boolean hasMore = false;
            List<Recommend_FocusImages_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String shortTitle = cursor.getString(cursor.getColumnIndex("shortTitle"));
                String longTitle = cursor.getString(cursor.getColumnIndex("longTitle"));
                String pic = cursor.getString(cursor.getColumnIndex("pic"));
                int trackId = cursor.getInt(cursor.getColumnIndex("trackId"));
                int type = cursor.getInt(cursor.getColumnIndex("type"));
                long albumId = cursor.getLong(cursor.getColumnIndex("albumId"));
                long specialId = cursor.getLong(cursor.getColumnIndex("specialId"));

                Recommend_FocusImages_List list = new Recommend_FocusImages_List();
                list.setShortTitle(shortTitle);
                list.setLongTitle(longTitle);
                list.setPic(pic);
                list.setTrackId(trackId);
                list.setType(type);
                list.setAlbumId(albumId);
                list.setSpecialId(specialId);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Recommend_Recyclerview_list的数据删除
     */
    public void deleteAll_Recommend_Recommend_Viewpager() {
        db.delete(Contant.RECOMMEND_VIEWPAGER_TABLENAME, null, null);
    }

    /**
     * Recommend_Recyclerview_list的数据更新
     *
     * @param datas
     */
    public void updateAll_Recommend_Recommend_Viewpager(List<Recommend_FocusImages_List> datas) {
        deleteAll_Recommend_Recommend_Viewpager();
        saveDatas_Recommend_Viewpager(datas);
    }

    //        ===================================SongMenu====================================

    /**
     * Recommend_Recyclerview_list_list的数据存储
     */
    public void saveDatas_SongMenu(List<Recommend_CategoryContents_List_List> datas) {
        ContentValues values = new ContentValues();
        for (Recommend_CategoryContents_List_List data : datas) {
            values.put("position", 0 + "");
            values.put("title", data.getTitle());
            values.put("subtitle", data.getSubtitle());
            values.put("key", data.getKey());
            values.put("nickname", data.getNickname());
            values.put("coverPath", data.getCoverPath());
            values.put("intro", data.getIntro());
            values.put("coverSmall", data.getCoverSmall());
            values.put("coverMiddle", data.getCoverMiddle());
            values.put("tracksCounts", data.getTracksCounts());
            values.put("albumId", data.getAlbumId());
            db.insert(Contant.SONGMENU_RECYCLERVIEW_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Recommend_Recyclerview_list_list插入一条数据
     */
    public void insert_SongMenu(Recommend_CategoryContents_List_List data) {
        ContentValues values = new ContentValues();
        values.put("title", data.getTitle());
        values.put("subtitle", data.getSubtitle());
        values.put("key", data.getKey());
        values.put("nickname", data.getNickname());
        values.put("coverPath", data.getCoverPath());
        values.put("intro", data.getIntro());
        values.put("coverSmall", data.getCoverSmall());
        values.put("coverMiddle", data.getCoverMiddle());
        values.put("tracksCounts", data.getTracksCounts());
        values.put("albumId", data.getAlbumId());
        db.insert(Contant.SONGMENU_RECYCLERVIEW_TABLENAME, null, values);
        values.clear();
    }


    /**
     * Recommend_Recyclerview_list_list的数据查询
     *
     * @return
     */
    public List<Recommend_CategoryContents_List_List> queryAll_SongMenu() {
        Cursor cursor = db.query(Contant.SONGMENU_RECYCLERVIEW_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Recommend_CategoryContents_List_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String subtitle = cursor.getString(cursor.getColumnIndex("subtitle"));
                String key = cursor.getString(cursor.getColumnIndex("key"));
                String nickname = cursor.getString(cursor.getColumnIndex("nickname"));
                String coverPath = cursor.getString(cursor.getColumnIndex("coverPath"));
                String intro = cursor.getString(cursor.getColumnIndex("intro"));
                String coverSmall = cursor.getString(cursor.getColumnIndex("coverSmall"));
                String coverMiddle = cursor.getString(cursor.getColumnIndex("coverMiddle"));
                int tracksCounts = cursor.getInt(cursor.getColumnIndex("tracksCounts"));
                int albumId = cursor.getInt(cursor.getColumnIndex("albumId"));

                Recommend_CategoryContents_List_List list = new Recommend_CategoryContents_List_List();
                list.setTitle(title);
                list.setSubtitle(subtitle);
                list.setKey(key);
                list.setNickname(nickname);
                list.setCoverPath(coverPath);
                list.setIntro(intro);
                list.setCoverSmall(coverSmall);
                list.setCoverMiddle(coverMiddle);
                list.setTracksCounts(tracksCounts);
                list.setAlbumId(albumId);
                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Recommend_Recyclerview_list_list的数据删除
     */
    public void deleteAll_SongMenu() {
        db.delete(Contant.SONGMENU_RECYCLERVIEW_TABLENAME, null, null);
    }

    /**
     * Recommend_Recyclerview_list_list的数据更新
     *
     * @param datas
     */
    public void updateAll_SongMenu(List<Recommend_CategoryContents_List_List> datas) {
        deleteAll_SongMenu();
        saveDatas_SongMenu(datas);
    }

    //        ===================================Anthology====================================

    /**
     * Anthology_Track的数据存储
     *
     * @param datas
     */
    public void saveDatas_Anthology_Track(List<Anthology_Track> datas) {
        ContentValues values = new ContentValues();
        for (int i = 0; i < datas.size(); i++) {
            values.put("position", i + "");
            values.put("totalCount", datas.get(i).getTotalCount());

            long id = db.insert(Contant.ANTHOLOGY_TRACK_TABLENAME, null, values);
            values.clear();

            saveDatas_Anthology_Track_List(datas.get(i).getList(), i + "");
        }
    }

    /**
     * Anthology_Track的数据查询
     *
     * @return
     */
    public List<Anthology_Track> queryAll_Anthology_Track() {
        Cursor cursor = db.query(Contant.ANTHOLOGY_TRACK_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Anthology_Track> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String position = cursor.getString(cursor.getColumnIndex("position"));
                int totalCount = cursor.getInt(cursor.getColumnIndex("totalCount"));

                Anthology_Track list = new Anthology_Track();
                list.setPosition(position);
                list.setTotalCount(totalCount);
                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Anthology_Track的数据删除
     */
    public void deleteAll_Anthology_Track() {
        db.delete(Contant.ANTHOLOGY_TRACK_TABLENAME, null, null);
    }

    /**
     * Anthology_Track的数据更新
     *
     * @param datas
     */
    public void updateAll_Anthology_Track(List<Anthology_Track> datas) {
        deleteAll_Anthology_Track();
        saveDatas_Anthology_Track(datas);
    }

    /**
     * Anthology_Track_List的数据存储
     *
     * @param datas
     */
    public void saveDatas_Anthology_Track_List(List<Anthology_Track_List> datas) {
        ContentValues values = new ContentValues();
        for (Anthology_Track_List data : datas) {

            values.put("trackId", data.getTrackId());
            values.put("duration", data.getDuration());
            values.put("playUrl32", data.getPlayUrl32());
            values.put("playUrl64", data.getPlayUrl64());
            values.put("downloadUrl", data.getDownloadUrl());
            values.put("title", data.getTitle());
            values.put("coverLarge", data.getCoverLarge());
            values.put("coverSmall", data.getCoverSmall());
            values.put("comments", data.getComments());
            values.put("playtimes", data.getPlaytimes());
            values.put("favoritesCounts", data.getFavoritesCounts());
            values.put("playsCounts", data.getPlaysCounts());
            values.put("commentsCounts", data.getCommentsCounts());
            values.put("nickname", data.getNickname());
            values.put("position", data.getPosition());

            long id = db.insert(Contant.ANTHOLOGY_TRACK_LIST_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Anthology_Track_List的数据存储
     *
     * @param datas
     */
    public void saveDatas_Anthology_Track_List(List<Anthology_Track_List> datas, String position) {
        ContentValues values = new ContentValues();
        for (Anthology_Track_List data : datas) {

            values.put("trackId", data.getTrackId());
            values.put("duration", data.getDuration());
            values.put("playUrl32", data.getPlayUrl32());
            values.put("playUrl64", data.getPlayUrl64());
            values.put("downloadUrl", data.getDownloadUrl());
            values.put("title", data.getTitle());
            values.put("coverLarge", data.getCoverLarge());
            values.put("coverSmall", data.getCoverSmall());
            values.put("comments", data.getComments());
            values.put("playtimes", data.getPlaytimes());
            values.put("favoritesCounts", data.getFavoritesCounts());
            values.put("playsCounts", data.getPlaysCounts());
            values.put("commentsCounts", data.getCommentsCounts());
            values.put("nickname", data.getNickname());
            values.put("position", position);

            long id = db.insert(Contant.ANTHOLOGY_TRACK_LIST_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Anthology_Track_List的数据查询
     *
     * @return
     */
    public List<Anthology_Track_List> queryAll_Anthology_Track_List() {
        Cursor cursor = db.query(Contant.ANTHOLOGY_TRACK_LIST_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Anthology_Track_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
              int trackId=cursor.getInt(cursor.getColumnIndex("trackId"));
                float duration =cursor.getFloat(cursor.getColumnIndex("duration"));
                String playUrl32 =cursor.getString(cursor.getColumnIndex("playUrl32"));
                String playUrl64=cursor.getString(cursor.getColumnIndex("playUrl64"));
                String downloadUrl=cursor.getString(cursor.getColumnIndex("downloadUrl"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String coverLarge=cursor.getString(cursor.getColumnIndex("coverLarge"));
                String coverSmall=cursor.getString(cursor.getColumnIndex("coverSmall"));
                int comments=cursor.getInt(cursor.getColumnIndex("comments"));
                int playtimes =cursor.getInt(cursor.getColumnIndex("playtimes"));
                int favoritesCounts =cursor.getInt(cursor.getColumnIndex("favoritesCounts"));
                int playsCounts=cursor.getInt(cursor.getColumnIndex("playsCounts"));
                int commentsCounts =cursor.getInt(cursor.getColumnIndex("commentsCounts"));
                String nickname =cursor.getString(cursor.getColumnIndex("nickname"));
                String position=cursor.getString(cursor.getColumnIndex("position"));

                Anthology_Track_List list=new Anthology_Track_List();
                list.setTrackId(trackId);
                list.setDuration(duration);
                list.setPlayUrl32(playUrl32);
                list.setPlayUrl64(playUrl64);
                list.setDownloadUrl(downloadUrl);
                list.setTitle(title);
                list.setCoverLarge(coverLarge);
                list.setCoverSmall(coverSmall);
                list.setComments(comments);
                list.setPlaytimes(playtimes);
                list.setFavoritesCounts(favoritesCounts);
                list.setPlaysCounts(playsCounts);
                list.setCommentsCounts(commentsCounts);
                list.setNickname(nickname);
                list.setPosition(position);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Anthology_Track_List的数据删除
     */
    public void deleteAll_Anthology_Track_List() {
        db.delete(Contant.ANTHOLOGY_TRACK_LIST_TABLENAME, null, null);
    }

    /**
     * Anthology_Track_List的数据更新
     *
     * @param datas
     */
    public void updateAll_Anthology_Track_List(List<Anthology_Track_List> datas) {
        deleteAll_Anthology_Track_List();
        saveDatas_Anthology_Track_List(datas);
    }

    /**
     * Anthology_Track_List查询position字段
     *
     * @return
     */
    public List<Anthology_Track_List> queryPostion_Anthology_Track_List(String position) {
        String sql = "select * from " + Contant.RECOMMEND_RECYCLERVIEW_LIST_LIST_TABLENAME + " where position = ? ";
        Cursor cursor = db.rawQuery(sql, new String[]{position});
        if (cursor != null) {
            List<Anthology_Track_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                int trackId=cursor.getInt(cursor.getColumnIndex("trackId"));
                float duration =cursor.getFloat(cursor.getColumnIndex("duration"));
                String playUrl32 =cursor.getString(cursor.getColumnIndex("playUrl32"));
                String playUrl64=cursor.getString(cursor.getColumnIndex("playUrl64"));
                String downloadUrl=cursor.getString(cursor.getColumnIndex("downloadUrl"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String coverLarge=cursor.getString(cursor.getColumnIndex("coverLarge"));
                String coverSmall=cursor.getString(cursor.getColumnIndex("coverSmall"));
                int comments=cursor.getInt(cursor.getColumnIndex("comments"));
                int playtimes =cursor.getInt(cursor.getColumnIndex("playtimes"));
                int favoritesCounts =cursor.getInt(cursor.getColumnIndex("favoritesCounts"));
                int playsCounts=cursor.getInt(cursor.getColumnIndex("playsCounts"));
                int commentsCounts =cursor.getInt(cursor.getColumnIndex("commentsCounts"));
                String nickname =cursor.getString(cursor.getColumnIndex("nickname"));
                String list_id=cursor.getString(cursor.getColumnIndex("position"));

                Anthology_Track_List list=new Anthology_Track_List();
                list.setTrackId(trackId);
                list.setDuration(duration);
                list.setPlayUrl32(playUrl32);
                list.setPlayUrl64(playUrl64);
                list.setDownloadUrl(downloadUrl);
                list.setTitle(title);
                list.setCoverLarge(coverLarge);
                list.setCoverSmall(coverSmall);
                list.setComments(comments);
                list.setPlaytimes(playtimes);
                list.setFavoritesCounts(favoritesCounts);
                list.setPlaysCounts(playsCounts);
                list.setCommentsCounts(commentsCounts);
                list.setNickname(nickname);
                list.setPosition(list_id);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Anthology_Album的数据存储
     */
    public void saveDatas_Anthology_Album(List<Anthology_Album> datas) {
        ContentValues values = new ContentValues();
        for (Anthology_Album data : datas) {
            values.put("title", data.getTitle());
            values.put("coverLarge", data.getCoverLarge());
            values.put("intro", data.getIntro());
            values.put("nickname", data.getNickname());
            values.put("tags", data.getTags());

            db.insert(Contant.ANTHOLOGY_ALBUM_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Anthology_Album插入一条数据
     */
    public void insert_Anthology_Album(Anthology_Album data) {
        ContentValues values = new ContentValues();
        values.put("title", data.getTitle());
        values.put("coverLarge", data.getCoverLarge());
        values.put("intro", data.getIntro());
        values.put("nickname", data.getNickname());
        values.put("tags", data.getTags());
        db.insert(Contant.ANTHOLOGY_ALBUM_TABLENAME, null, values);
        values.clear();
    }


    /**
     * Anthology_Album的数据查询
     *
     * @return
     */
    public List<Anthology_Album> queryAll_Anthology_Album() {
        Cursor cursor = db.query(Contant.ANTHOLOGY_ALBUM_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Anthology_Album> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String coverLarge = cursor.getString(cursor.getColumnIndex("coverLarge"));
                String intro = cursor.getString(cursor.getColumnIndex("intro"));
                String nickname = cursor.getString(cursor.getColumnIndex("nickname"));
                String tags = cursor.getString(cursor.getColumnIndex("tags"));


                Anthology_Album list = new Anthology_Album();
                list.setTitle(title);
                list.setNickname(nickname);
                list.setIntro(intro);
                list.setCoverLarge(coverLarge);
                list.setTags(tags);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Anthology_Album的数据删除
     */
    public void deleteAll_Anthology_Album() {
        db.delete(Contant.ANTHOLOGY_ALBUM_TABLENAME, null, null);
    }

    /**
     * Recommend_Recyclerview_list_list的数据更新
     *
     * @param datas
     */
    public void updateAll_Anthology_Album(List<Anthology_Album> datas) {
        deleteAll_Anthology_Album();
        saveDatas_Anthology_Album(datas);
    }


    //        ===================================Songdetail====================================

    /**
     * Songdetail_Info的数据存储
     *
     * @param datas
     */
    public void saveDatas_Songdetail_Info(List<SongDetail_Info> datas) {
        ContentValues values = new ContentValues();
        for (int i = 0; i < datas.size(); i++) {

            values.put("position", i+"");
            values.put("coverPathBig", datas.get(i).getCoverPathBig());
            values.put("intro", datas.get(i).getIntro());
            values.put("title", datas.get(i).getTitle());
            values.put("nickname", datas.get(i).getNickname());
            values.put("smallLogo", datas.get(i).getSmallLogo());
            values.put("personalSignature", datas.get(i).getPersonalSignature());
            values.put("contentType", datas.get(i).getContentType());

            long id = db.insert(Contant.SONGDETAIL_INFO_TABLENAME, null, values);
            values.clear();

        }
    }

    /**
     * Songdetail_Info的数据查询
     *
     * @return
     */
    public List<SongDetail_Info> queryAll_Songdetail_Info() {
        Cursor cursor = db.query(Contant.SONGDETAIL_INFO_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<SongDetail_Info> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                int contentType=cursor.getInt(cursor.getColumnIndex("contentType"));
                String coverPathBig=cursor.getString(cursor.getColumnIndex("coverPathBig"));
                String intro=cursor.getString(cursor.getColumnIndex("intro"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String nickname =cursor.getString(cursor.getColumnIndex("nickname"));
                String smallLogo=cursor.getString(cursor.getColumnIndex("smallLogo"));
                String personalSignature=cursor.getString(cursor.getColumnIndex("personalSignature"));
                String position=cursor.getString(cursor.getColumnIndex("position"));


                SongDetail_Info list = new SongDetail_Info();
                list.setContentType(contentType);
                list.setCoverPathBig(coverPathBig);
                list.setIntro(intro);
                list.setTitle(title);
                list.setNickname(nickname);
                list.setSmallLogo(smallLogo);
                list.setPersonalSignature(personalSignature);
                list.setPosition(position);
                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Songdetail_Info的数据删除
     */
    public void deleteAll_Songdetail_Info() {
        db.delete(Contant.SONGDETAIL_INFO_TABLENAME, null, null);
    }

    /**
     * Songdetail_Info的数据更新
     *
     * @param datas
     */
    public void updateAll_Songdetail_Info(List<SongDetail_Info> datas) {
        deleteAll_Songdetail_Info();
        saveDatas_Songdetail_Info(datas);
    }

    /**
     * Songdetail_Recyclerview的数据存储
     *
     * @param datas
     */
    public void saveDatas_Songdetail_Recyclerview(List<Anthology_Track_List> datas) {
        ContentValues values = new ContentValues();

        for (Anthology_Track_List data : datas) {

            values.put("trackId", data.getTrackId());
            values.put("duration", data.getDuration());
            values.put("playUrl32", data.getPlayUrl32());
            values.put("playUrl64", data.getPlayUrl64());
            values.put("downloadUrl", data.getDownloadUrl());
            values.put("title", data.getTitle());
            values.put("coverLarge", data.getCoverLarge());
            values.put("coverSmall", data.getCoverSmall());
            values.put("comments", data.getComments());
            values.put("playtimes", data.getPlaytimes());
            values.put("favoritesCounts", data.getFavoritesCounts());
            values.put("playsCounts", data.getPlaysCounts());
            values.put("commentsCounts", data.getCommentsCounts());
            values.put("nickname", data.getNickname());
            values.put("position", data.getPosition());

            long id = db.insert(Contant.SONGDETAIL_RECYCLERVIEW_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Songdetail_Recyclerview的数据存储
     *
     * @param datas
     */
    public void saveDatas_Songdetail_Recyclerview(List<Anthology_Track_List> datas, String position) {
        ContentValues values = new ContentValues();
        for (Anthology_Track_List data : datas) {

            values.put("trackId", data.getTrackId());
            values.put("duration", data.getDuration());
            values.put("playUrl32", data.getPlayUrl32());
            values.put("playUrl64", data.getPlayUrl64());
            values.put("downloadUrl", data.getDownloadUrl());
            values.put("title", data.getTitle());
            values.put("coverLarge", data.getCoverLarge());
            values.put("coverSmall", data.getCoverSmall());
            values.put("comments", data.getComments());
            values.put("playtimes", data.getPlaytimes());
            values.put("favoritesCounts", data.getFavoritesCounts());
            values.put("playsCounts", data.getPlaysCounts());
            values.put("commentsCounts", data.getCommentsCounts());
            values.put("nickname", data.getNickname());
            values.put("position", position);

            long id = db.insert(Contant.SONGDETAIL_RECYCLERVIEW_TABLENAME, null, values);
            values.clear();
        }
    }

    /**
     * Songdetail_Recyclerview的数据查询
     *
     * @return
     */
    public List<Anthology_Track_List> queryAll_Songdetail_Recyclerview() {
        Cursor cursor = db.query(Contant.SONGDETAIL_RECYCLERVIEW_TABLENAME, null, null, null, null, null, null);
        if (cursor != null) {
            List<Anthology_Track_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                int trackId=cursor.getInt(cursor.getColumnIndex("trackId"));
                float duration =cursor.getFloat(cursor.getColumnIndex("duration"));
                String playUrl32 =cursor.getString(cursor.getColumnIndex("playUrl32"));
                String playUrl64=cursor.getString(cursor.getColumnIndex("playUrl64"));
                String downloadUrl=cursor.getString(cursor.getColumnIndex("downloadUrl"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String coverLarge=cursor.getString(cursor.getColumnIndex("coverLarge"));
                String coverSmall=cursor.getString(cursor.getColumnIndex("coverSmall"));
                int comments=cursor.getInt(cursor.getColumnIndex("comments"));
                int playtimes =cursor.getInt(cursor.getColumnIndex("playtimes"));
                int favoritesCounts =cursor.getInt(cursor.getColumnIndex("favoritesCounts"));
                int playsCounts=cursor.getInt(cursor.getColumnIndex("playsCounts"));
                int commentsCounts =cursor.getInt(cursor.getColumnIndex("commentsCounts"));
                String nickname =cursor.getString(cursor.getColumnIndex("nickname"));
                String position=cursor.getString(cursor.getColumnIndex("position"));

                Anthology_Track_List list=new Anthology_Track_List();
                list.setTrackId(trackId);
                list.setDuration(duration);
                list.setPlayUrl32(playUrl32);
                list.setPlayUrl64(playUrl64);
                list.setDownloadUrl(downloadUrl);
                list.setTitle(title);
                list.setCoverLarge(coverLarge);
                list.setCoverSmall(coverSmall);
                list.setComments(comments);
                list.setPlaytimes(playtimes);
                list.setFavoritesCounts(favoritesCounts);
                list.setPlaysCounts(playsCounts);
                list.setCommentsCounts(commentsCounts);
                list.setNickname(nickname);
                list.setPosition(position);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }

    /**
     * Songdetail_Recyclerview的数据删除
     */
    public void deleteAll_Songdetail_Recyclerview() {
        db.delete(Contant.SONGDETAIL_RECYCLERVIEW_TABLENAME, null, null);
    }

    /**
     * Songdetail_Recyclerview的数据更新
     *
     * @param datas
     */
    public void updateAll_Songdetail_Recyclerview(List<Anthology_Track_List> datas) {
        deleteAll_Anthology_Track_List();
        saveDatas_Anthology_Track_List(datas);
    }

    /**
     * Songdetail_Recyclerview查询position字段
     *
     * @return
     */
    public List<Anthology_Track_List> queryPostion_Songdetail_Recyclerview(String position) {
        String sql = "select * from " + Contant.SONGDETAIL_RECYCLERVIEW_TABLENAME + " where position = ? ";
        Cursor cursor = db.rawQuery(sql, new String[]{position});
        if (cursor != null) {
            List<Anthology_Track_List> datas = new ArrayList<>();
            while (cursor.moveToNext()) {
                int trackId=cursor.getInt(cursor.getColumnIndex("trackId"));
                float duration =cursor.getFloat(cursor.getColumnIndex("duration"));
                String playUrl32 =cursor.getString(cursor.getColumnIndex("playUrl32"));
                String playUrl64=cursor.getString(cursor.getColumnIndex("playUrl64"));
                String downloadUrl=cursor.getString(cursor.getColumnIndex("downloadUrl"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String coverLarge=cursor.getString(cursor.getColumnIndex("coverLarge"));
                String coverSmall=cursor.getString(cursor.getColumnIndex("coverSmall"));
                int comments=cursor.getInt(cursor.getColumnIndex("comments"));
                int playtimes =cursor.getInt(cursor.getColumnIndex("playtimes"));
                int favoritesCounts =cursor.getInt(cursor.getColumnIndex("favoritesCounts"));
                int playsCounts=cursor.getInt(cursor.getColumnIndex("playsCounts"));
                int commentsCounts =cursor.getInt(cursor.getColumnIndex("commentsCounts"));
                String nickname =cursor.getString(cursor.getColumnIndex("nickname"));
                String list_id=cursor.getString(cursor.getColumnIndex("position"));

                Anthology_Track_List list=new Anthology_Track_List();
                list.setTrackId(trackId);
                list.setDuration(duration);
                list.setPlayUrl32(playUrl32);
                list.setPlayUrl64(playUrl64);
                list.setDownloadUrl(downloadUrl);
                list.setTitle(title);
                list.setCoverLarge(coverLarge);
                list.setCoverSmall(coverSmall);
                list.setComments(comments);
                list.setPlaytimes(playtimes);
                list.setFavoritesCounts(favoritesCounts);
                list.setPlaysCounts(playsCounts);
                list.setCommentsCounts(commentsCounts);
                list.setNickname(nickname);
                list.setPosition(list_id);

                datas.add(list);
            }
            cursor.close();
            return datas;
        }
        return null;
    }
}
